'use strict'

const { Controller } = require('egg')

class home extends Controller {
    async index() {
        const { ctx } = this
        const [result] = await ctx.app.mysql.select('background', {
            columns: ['cover'],
            orders: [
                ['id', 'desc']
            ],
            limit: 1
        })

        ctx.returnBody(200, '获取成功', { ...result })
    }
    async create() {
        const { ctx } = this
        const { cover } = ctx.request.body

        if (!await ctx.validate('background', { cover })) return

        await ctx.app.mysql.insert('background', { cover })

        ctx.returnBody(200, '更换成功')
    }
}

module.exports = home